package pipecleaner.agent.cli;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import pipecleaner.agent.core.Agent;
import pipecleaner.agent.core.HttpAgent;

/**
 * Command line entry point for Agent.
 */
public class Main
{
    private static final Log log = LogFactory.getLog(Main.class);
	private int port;
    
    public Main (String port) {
    	setPort(port);
	}

	public static void main (String [] args) throws Exception {
	    // TODO check args
	    // TODO check environment
		String port = args[0];
		Main main = new Main(port);
	    main.startAgent();
	}

	private void setPort (String portArg)	{
		if (portArg != null) {
			this.port = Integer.parseInt(portArg);
		}
	}

	/**
     * Starts up the agent
     */
    private void startAgent () throws Exception
    {
    	// TODO this should probably invoke a factory to build the proper agent type
        Agent agent = new HttpAgent(port);
        agent.start();
    }    
}
